<?php
namespace app\horoscope\controller;

//use \app\check\controller\Check;

class Shishen extends \think\Controller
{
    // 十神表
    private $shishen = [
        '甲' => [
            '甲' => '比肩',
            '乙' => '劫财',
            '丙' => '偏印',
            '丁' => '正印',
            '戊' => '七杀',
            '己' => '正官',
            '庚' => '偏财',
            '辛' => '正财',
            '壬' => '食神',
            '癸' => '伤官',
        ],
        '乙' => [
            '甲' => '劫财',
            '乙' => '比肩',
            '丙' => '正印',
            '丁' => '偏印',
            '戊' => '正官',
            '己' => '七杀',
            '庚' => '正财',
            '辛' => '偏财',
            '壬' => '伤官',
            '癸' => '食神',
        ],
        '丙' => [
            '甲' => '食神',
            '乙' => '伤官',
            '丙' => '比肩',
            '丁' => '劫财',
            '戊' => '偏印',
            '己' => '正印',
            '庚' => '七杀',
            '辛' => '正官',
            '壬' => '偏财',
            '癸' => '正财',
        ],
        '丁' => [
            '甲' => '伤官',
            '乙' => '食神',
            '丙' => '劫财',
            '丁' => '比肩',
            '戊' => '正印',
            '己' => '偏印',
            '庚' => '正官',
            '辛' => '七杀',
            '壬' => '正财',
            '癸' => '偏财',
        ],
        '戊' => [
            '甲' => '偏财',
            '乙' => '正财',
            '丙' => '食神',
            '丁' => '伤官',
            '戊' => '比肩',
            '己' => '劫财',
            '庚' => '偏印',
            '辛' => '正印',
            '壬' => '七杀',
            '癸' => '正官',
        ],
        '己' => [
            '甲' => '正财',
            '乙' => '偏财',
            '丙' => '伤官',
            '丁' => '食神',
            '戊' => '劫财',
            '己' => '比肩',
            '庚' => '正印',
            '辛' => '偏印',
            '壬' => '正官',
            '癸' => '七杀',
        ],
        '庚' => [
            '甲' => '七杀',
            '乙' => '正官',
            '丙' => '偏财',
            '丁' => '正财',
            '戊' => '食神',
            '己' => '伤官',
            '庚' => '比肩',
            '辛' => '劫财',
            '壬' => '偏印',
            '癸' => '正印',
        ],
        '辛' => [
            '甲' => '正官',
            '乙' => '七杀',
            '丙' => '正财',
            '丁' => '偏财',
            '戊' => '伤官',
            '己' => '食神',
            '庚' => '劫财',
            '辛' => '比肩',
            '壬' => '正印',
            '癸' => '偏印',
        ],
        '壬' => [
            '甲' => '偏印',
            '乙' => '正印',
            '丙' => '七杀',
            '丁' => '正官',
            '戊' => '偏财',
            '己' => '正财',
            '庚' => '食神',
            '辛' => '伤官',
            '壬' => '比肩',
            '癸' => '劫财',
        ],
        '癸' => [
            '甲' => '正印',
            '乙' => '偏印',
            '丙' => '正官',
            '丁' => '七杀',
            '戊' => '正财',
            '己' => '偏财',
            '庚' => '伤官',
            '辛' => '食神',
            '壬' => '劫财',
            '癸' => '比肩',
        ],
    ];
    // 藏干
    private $canggan = [
        '亥' => ['壬', '甲'],
        '子' => ['癸'],
        '丑' => ['己', '癸', '辛'],
        '寅' => ['甲', '丙', '戊'],
        '卯' => ['乙'],
        '辰' => ['戊', '己', '癸'],
        '巳' => ['丙', '戊', '庚'],
        '午' => ['丁', '己',],
        '未' => ['己', '丁', '乙'],
        '申' => ['庚', '壬', '戊'],
        '酉' => ['辛'],
        '戌' => ['戊', '丁', '辛']
    ];
//    private $bazi = [
//        1=>'甲',2=>'戌',
//        3=>'丙',4=>'寅',
//        5=>'丙',6=>'戌',
//        7=>'庚',8=>'寅'
//    ];
    private $bazi = [
        1 => '甲', 2 => '戌',
        3 => '丙', 4 => '子',
        5 => '丁', 6 => '亥',
        7 => '丁', 8 => '未'
    ];

    public function __construct()
    {
//        parent::__construct();// 接口调用验证

    }

    public function getShishen()
    {
        $ret = [];
        for($i = 1;$i < 9; $i++)
        {
            if($i == 5) continue;
            $rigan = $this->bazi[5];
            $other = $this->bazi[$i];
//            $loc = ceil($i / 2);
            // 干
            if($i % 2 == 1)
            {
                $ret['zhu'][$i] = [
                    'a'=>$rigan,
                    'b'=>$other,
                    'relation'=>$this->shishen[$other][$rigan],
                    'loc'=>$i,
                ];
            }
            // 藏干
            else
            {
                foreach ($this->canggan[$other] as $k => $g)
                {
                    $benqi = $k === 0 ? true : false;
                    $ret['cang'][] = [
                        'a'=>$rigan,
                        'b'=>$other,
                        'relation'=>$this->shishen[$g][$rigan],
                        'loc'=>$i,
                        'benqi'=>$benqi
                    ];
                }
            }
        }
        return json(['code'=>200,'data'=>$ret,'msg'=>'Success.']);
    }

}
